<template>
	<view class="page">
		<view class="content">
			<view class="text-area">
				<up-input placeholder="阳阳阳阳阳阳,1阳2阴(111122),或卦名" border="surround" v-model="code"
					placeholderStyle="color: #ece9e6;font-size: 10px;font-style: italic;" @blur="searchInput" />
			</view>
			<view class="content_list block_list">
				<view v-for="i in guaArr" :key="i.number" class="content-item">
					<view class="guaxiang">
						<view v-for="icode in i.code" :key="i.code">
							<view :class="icode == '1' ? 'yi gua_box' : 'er gua_box'">
								<view class="block_box" />
								<view class="block_box" />
							</view>
						</view>
					</view>
					<view class="text">{{ i.name }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import gua from '../../mock/64卦.json'
	export default {
		data() {
			return {
				title: '搜索',
				code: '',
				guaJson: gua,
				newArr: [],
				guaArr: []
			}
		},
		onLoad() {
			this.guaArr = gua.gua
		},
		methods: {
			searchInput(item) {
				if (this.code) {
					// 确保this.code存在
					// 使用filter代替map，因为filter只返回满足条件的元素
					const filteredArr = this.guaJson.gua.filter(item => {
						console.log(item.number, this.code)
						// 检查多个属性是否包含this.code
						return (
							item.name.includes(this.code) ||
							item.number.includes(this.code) ||
							item.code.includes(this.code) ||
							item.type.includes(this.code)
						)
					})

					// 使用filteredArr，它只包含满足条件的元素
					console.log(filteredArr)
					this.guaArr = filteredArr
				} else {
					console.log('this.code is not defined or empty')
					this.guaArr = this.guaJson.gua
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	/* 列表块 */
	.block_list {
		background: #ffffff;
		box-shadow: 0rpx 3rpx 7rpx 1rpx rgba(55, 51, 95, 0.08);
		border-radius: 32rpx;
		padding: 40rpx 0;

		// margin: 0rpx 31rpx;
		// padding: 30rpx;
		:deep(.u-form-item__body__left__content__label) {
			font-size: 26rpx !important;
		}

		:deep(.u-form-item__body__right__message) {
			margin-left: 0 !important;
		}
	}

	input::-placeholder,
	textarea::-placeholder {
		color: #fff;
		/* 示例颜色 */
		font-size: 14px;
		/* 示例字体大小 */
	}

	.content {
		display: flex;
		flex-direction: column;
		/* align-items: center; */
		/* justify-content: center; */
	}

	.text-area {
		width: 90%;
		position: fixed;
		// margin-bottom: 20px;
		color: #000;
		display: flex;
		// background-color: aliceblue;
		border-radius: 10px;
		padding: 10px 0;
		display: flex;
		align-items: center;
		// justify-content: space-around;
		// background-image:
		// 	radial-gradient(circle at 50% 50%,
		// 		#fff 0%, #fff 40%,
		// 		#000 40.1%, #000 60%,
		// 		#fff 60.1%, #fff 100%);
		background-image: linear-gradient(to bottom right, #ffffff, #000000);
		// background-image:
		// 	radial-gradient(circle at 50% 50%, #ffffff 40%, #000000 41%),
		// 	/* 白色小圆（阳） */
		// 	radial-gradient(circle at 50% 50%, #000000 40%, #ffffff 41%);
		// /* 黑色小圆（阴） */
		// background-size: 100% 100%;
		// background-repeat: no-repeat;

		.placeholderStyle {
			color: #ece9e6;
			/* 浅灰色 */
			font-size: 8px;
			/* 自定义字体大小 */
			font-style: italic;
			/* 斜体 */
		}

		.uni-input {
			border: 1px solid #ece9e6;
			width: 80%;
		}

		button {
			height: 60rpx;
			line-height: 60rpx;
			margin: 0;
		}
	}

	.title {
		font-size: 32rpx;
	}

	.gua_box {
		display: flex;
		align-items: center;
		width: 12vw;
		padding-bottom: 2px;

		.block_box {
			width: 50%;
			height: 10upx;
			background-color: #000;
		}
	}

	.yi {}

	.er {
		justify-content: space-between;

		.block_box {
			width: 40%;
		}
	}

	.content_list {
		display: flex;
		flex-wrap: wrap;
		align-items: cneter;
		margin-top: 120rpx;

		.content-item {
			width: 25%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
		}
	}
</style>